package com.backend.system.common.processor;


import com.backend.system.common.enums.ActionTypeEnum;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 处理器工厂
 *
 * @author feng
 */
public class ProcessorFactory {

    private static final Map<ActionTypeEnum, AbstractProcessorTemplate<?, ?>> PROCESSOR_MAP = new ConcurrentHashMap<>();

    public static <T, R> void register(ActionTypeEnum actionTypeEnum, AbstractProcessorTemplate<T, R> processor) {
        PROCESSOR_MAP.put(actionTypeEnum, processor);
    }

    public static <T, R> AbstractProcessorTemplate<T, R> getProcessor(ActionTypeEnum actionTypeEnum) {
        return (AbstractProcessorTemplate<T, R>) PROCESSOR_MAP.get(actionTypeEnum);
    }

    private ProcessorFactory() {
    }
}
